package P150;

import java.util.HashMap;
import java.util.Map;

/**
 * @author LiangMu
 * @version \$Id: P37.java, v 0.1, 2024年07月06日 00:24 LiangMu Exp $$
 */
public class P37 {

    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> map1 = new HashMap<>();
        Map<Character, Character> map2 = new HashMap<>();
        char[] source = s.toCharArray();
        char[] target = t.toCharArray();
        for (int i = 0; i < source.length; i++) {
            if (map1.containsKey(source[i])) {
                if (map1.get(source[i]) != target[i]) {
                    return false;
                }
            } else {
                map1.put(source[i], target[i]);
            }

            if (map2.containsKey(target[i])) {
                if (map2.get(target[i]) != source[i]) {
                    return false;
                }
            } else {
                map2.put(target[i], source[i]);
            }
        }
        return true;
    }

}
